//
//  FQSesameTableViewCell.swift
//  SwiftProject
//
//  Created by 董駸 on 2023/4/12.
//

import UIKit

class FQSesameTableViewCell: BaseTableViewCell {

    var btnArray : [QMUIButton] = []
    var checkBlock : (()->Void)?
    var model : FQFillInfoModel!

    let array : [String] = ["600分以下", "601-649分", "650-700分", "700分以上"]

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        
        for (index, str) in array.enumerated() {
            let button = QMUIButton(title: str, titleColor: .color102, font: .rSFont(13))
            button.setBackgroundWithColor(.color238, for: .normal)
            button.setBackgroundWithColor(.white, for: .selected)
            button.setTitleColor(.colorMain, for: .selected)
            button.clipsToBounds = true
            button.layer.cornerRadius = 4
            button.addTarget(self, action: #selector(buttonClick(_:)), for: .touchUpInside)
            button.layer.borderColor = UIColor.colorMain.cgColor
            button.layer.borderWidth = 0
            button.tag = 10 + index
            contentView.addSubview(button)
            
            btnArray.append(button)
        }
        btnArray.snp.makeConstraints { make in
            make.height.equalTo(35)
        }
        btnArray.snp.distributeSudokuViews(fixedLineSpacing: 10, fixedInteritemSpacing: 10, warpCount: 3, edgeInset: UIEdgeInsets(top: 17, left: 26, bottom: 15, right: 26))
    }
    
    @objc func buttonClick(_ button : QMUIButton) {
        for btn in btnArray {
            btn.isSelected = false
            btn.layer.borderWidth = 0
        }
        button.layer.borderWidth = 0.5
        button.isSelected = true
        model.detail = array[button.tag - 10]
        checkBlock?()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
